#include <bits/stdc++.h>
using namespace std;

void bfs();
int a[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int a2[4][2] = {{2, 0}, {-2, 0}, {0, 2}, {0, -2}};
int vis[205][205];
char b[205][205];

struct node
{
    int line;
    int row;
    int step;
    friend bool operator<(const node &t1, const node &t2)
    {
        return (t1.step < t2.step);
    }
} p, r[105];

int m, n;
int num1;
int xend, yend;

int main()
{
    while (~scanf("%d %d", &n, &m))
    {
        memset(vis, 0, sizeof(vis));
        for (int i = 0; i < n; i++)
        {
            getchar();
            for (int j = 0; j < m; j++)
            {
                scanf("%c", &b[i][j]);
            }
        }
        scanf("%d %d", &p.line, &p.row);
        p.line--;
        p.row--;
        scanf("%d %d", &xend, &yend);
        xend--;
        yend--;
        bfs();
    }
    return 0;
}

void bfs()
{
    priority_queue<node> que;
    node cur, nex;
    cur.line = p.line;
    cur.row = p.row;
    cur.step = 0;
    vis[cur.row][cur.line] = 1;
    que.push(cur);
    while (!que.empty())
    {
        cur = que.top();
        que.pop();
        if (cur.line == xend && cur.row == yend)
        {
            if(cur.step >= 3)
            {
                cur.step --;
            }
            printf("%d\n", cur.step);
            return;
        }
        for (int i = 0; i < 4; i++)
        {
            nex.line = cur.line + a[i][0];
            nex.row = cur.row + a[i][1];
            if (nex.line >= 0 && nex.row < n && nex.line < m && nex.row >= 0 && !vis[nex.row][nex.line] && b[nex.row][nex.line] == '.')
            {
                vis[nex.row][nex.line] = 1;
                nex.step = cur.step + 1;
                que.push(nex);
            }
            else if (nex.line >= 0 && nex.row < n && nex.line < m && nex.row >= 0 && !vis[nex.row][nex.line] && b[nex.row][nex.line] == '*')
            {
                nex.line = cur.line + a2[i][0];
                nex.row = cur.row + a2[i][1];
                if (nex.line >= 0 && nex.row < n && nex.line < m && nex.row >= 0 && !vis[nex.row][nex.line] && b[nex.row][nex.line] == '.cur')
                {
                    vis[nex.row][nex.line] = 1;
                    nex.step = cur.step + 1;
                    que.push(nex);
                }
            }
        }
    }
    printf("-1\n");
    return;
}
